package com.whc.gulimall.order.vo;

import cn.hutool.core.collection.CollUtil;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author angaoen
 */
@Data
public class OrderConfirmVo {

    /**
     * 收货地址列表
     */
    private List<MemberReceiveAddressVo> addressList;

    /**
     * 商品列表
     */
    private List<ProductVo> productList;

    /**
     * 优惠券
     */
    private Integer integration;

    /**
     * 令牌
     */
    private String orderToken;

    /**
     * 订单金额
     */
    @Setter(AccessLevel.NONE)
    @Getter(AccessLevel.NONE)
    private BigDecimal total;

    /**
     * 应付金额
     */
    @Setter(AccessLevel.NONE)
    @Getter(AccessLevel.NONE)
    private BigDecimal payPrice;

    /**
     * 商品总数
     */
    @Setter(AccessLevel.NONE)
    @Getter(AccessLevel.NONE)
    private Integer count;

    public BigDecimal getTotal() {
        if (CollUtil.isNotEmpty(this.productList)) {
            return this.productList.stream().map(ProductVo::getTotalPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
        }
        return BigDecimal.ZERO;
    }

    public BigDecimal getPayPrice() {
        return this.getTotal();
    }

    public Integer getCount() {
        return this.productList.stream().mapToInt(ProductVo::getCount).sum();
    }
}
